<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../js/vue.min.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
</head>
<body>
<div id="app">
    <el-container>
        <el-header >
            <h1>XXXX后台管理系统</h1>
        </el-header>
        <el-container>
            <el-aside style="width: 200px">
                <el-menu @select="selectMenu"
                    default-active="2"
                    class="el-menu-vertical-demo">
                    <el-menu-item v-for="menu in menus"  :index="menu.name">
                        <i class="el-icon-location"></i>
                        <span>{{menu.name}}</span>
                    </el-menu-item>
<!--                <el-menu-item index="2">-->
<!--                    <i class="el-icon-menu"></i>-->
<!--                    <span slot="title">用户管理</span>-->
<!--                </el-menu-item>-->
<!--                <el-menu-item index="3" disabled>-->
<!--                    <i class="el-icon-document"></i>-->
<!--                    <span slot="title">layout.html</span>-->
<!--                </el-menu-item>-->
<!--                <el-menu-item index="4">-->
<!--                    <i class="el-icon-setting"></i>-->
<!--                    <span slot="title">导航四</span>-->
<!--                </el-menu-item>-->
            </el-menu>
            </el-aside>
            <el-main>
                <el-tabs v-model="currentTab" type="border-card" style="height: 100%">
                <el-tab-pane v-for=" tab in tabs " :label="tab.name"
                    :key="tab.name" :name="tab.name">
                    <iframe :src="tab.url" height="100%" width="100%"></iframe>
                </el-tab-pane>
<!--                <el-tab-pane label="配置管理">配置管理</el-tab-pane>-->
<!--                <el-tab-pane label="角色管理">角色管理</el-tab-pane>-->
<!--                <el-tab-pane label="定时任务补偿">定时任务补偿</el-tab-pane>-->
            </el-tabs>
            </el-main>
        </el-container>
    </el-container>
</div>


<script>
    var v = new Vue({
        el:"#app",
        data:{
            menus : [
                {name:"布局管理",url:"layout.html"},
                {name:"分页控件",url:"../vue/d0311/分页控件.html"},
                {name:"折叠面板",url:"../vue/d0311/折叠面板.html"},
                {name:"分页查询",url:"../vue/d0312/分页查询.html"},
                {name:"图书管理",url:"../ElementUI/图书管理.html"},
            ],
            tabs:[ ],
            currentTab :""
        },
        methods:{
            selectMenu(name){
                //查找是否已经打开该页
                let tab = this.tabs.find(tab=>{
                    if(tab.name == name){
                        return tab;
                    }
                });
                //如果tab 不为undefined，表示已经打开tab
                if (tab){
                    //直接选中该标签
                    this.currentTab = name;
                    return;
                }
                //在菜单数组中查找菜单对象
                this.menus.forEach(menu=>{
                    if (menu.name == name){
                        this.tabs.push({
                            name:name,
                            url:menu.url
                        });
                        //设置当前页
                        this.currentTab = name;
                    }
                })
            }
        }

    })
</script>

</body>
</html>


<style>
    html,body,#app{
        height: 100%;
        padding: 0px;
        margin: 0px;
    }


    .el-container{
        height: 100%;
    }

    .el-tabs__content{
        height: calc(100% - 68px);
    }

    .el-tab-pane{
        height: 100%;
    }


</style>